package com.znz.domain;

import org.springframework.roo.addon.javabean.RooJavaBean;
import org.springframework.roo.addon.jpa.activerecord.RooJpaActiveRecord;
import org.springframework.roo.addon.tostring.RooToString;

import javax.persistence.Column;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Query;
import javax.persistence.TypedQuery;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.Set;

/**
 * Created by IntelliJ IDEA.
 * User: johnson
 * Date: 5/6/15
 * Time: 3:11 下午
 */

@RooJavaBean
@RooToString
@RooJpaActiveRecord(versionField = "", identifierColumn = "id", identifierField = "id", table = "t_customer")

public class Tcustomer {

	//登录名
    @Column(name="user_Name")
	private String userName;

	//登录密码
    @Column(name="password")
	private String password;
	//	客服别名
    @Column(name="user_Alias")
	private String userAlias;
	//擅长
    @Column(name="is_good_at")
	private String is_good_at;
	//	联系电话
    @Column(name="user_Phone")
	private String userPhone;
	//	提成比例
    @Column(name="percentage")
	private String percentage;
	//	客服等级
    @Column(name="user_Level")
	private String userLevel;
	//	状态 删除-1 正常0 注销1
    @Column(name="state")
	private int state;
	//	修改时间
    @Column(name="update_time")
	private Date update_time;
	//	创建时间
    @Column(name="create_time")
	private Date create_time;


    public static List<Tcustomer> getTcustomerByWhere(String where,Map<String,Object> params,int firstResult,int maxResults){
        StringBuilder str_Quert=new StringBuilder("SELECT o FROM Tcustomer o   where o.state!=-1  ");
        str_Quert.append(where);
        str_Quert.append(" order by o.id ");
        TypedQuery<Tcustomer> query=entityManager().createQuery(str_Quert.toString(),Tcustomer.class).setFirstResult(firstResult).setMaxResults(maxResults);
        if(null!=params && params.size()>0){
            Set<String> keySet=params.keySet();
            for (String key:keySet){
                query.setParameter(key,params.get(key));
            }
            return query.getResultList();
        }
        return query.getResultList();
    }

    public static boolean delCustomerService(Long cId){
        boolean flag=false;
        try {
            String sql="update t_customer set state=1 where id=?";
            Query query=entityManager().createNativeQuery(sql);
            query.setParameter(1,cId);
            int i=query.executeUpdate();
            if(i>0){
                  flag=true;
            }
        } catch (Exception e) {
            e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
            flag=false;
        }
        return  flag;
    }
}
